import XMonad.Util.EZConfig
import XMonad.Hooks.DynamicLog
import XMonad.Util.Run(spawnPipe)
import XMonad.Layout.Spacing

import XMonad
import System.IO

main = xmonad =<< statusBar "xmobar /home/jahor/.config/xmobar/xmobar.hs" myPP toggleStrutsKey defaults


xmobarEscape = concatMap doubleLts
  where doubleLts '<' = "<<"
        doubleLts x   = [x]

myWorkspaces :: [String]
myWorkspaces = clickable . (map xmobarEscape) $ ["I", "II", "III", "IV", "V"]
  where clickable l = [ "<action=xdotool key super+" ++ show (n) ++ ">" ++ ws ++ "</action>" |
                        (i,ws) <- zip [1..5] l,                                        
                        let n = i ]

dmenu = "dmenu_run -c -f -l 3 -p '~>' -fn 'InputMono-17:normal' -nf '#2a2a2a' -sb '#bedbf0' -nb '#e4e4e4' -sf '#2a2a2a'"

myLayout = tiled ||| Mirror tiled ||| Full
  where
    tiled = spacing 5 $ Tall nmaster delta ratio
    nmaster = 1
    ratio = 1/2
    delta = 3/100

  
defaults = defaultConfig { 
	   terminal             = "kitty --single-instance"
	   , layoutHook         = myLayout
	   , modMask            = mod4Mask
	   , borderWidth        = 0
	   , normalBorderColor  = "#e4e4e4"   
	   , focusedBorderColor = "#2a2a2a"
           , startupHook        = spawn "compton --vsync --backend glx"
	   , workspaces         = myWorkspaces

   } `additionalKeys` 
		   [((mod4Mask, xK_x),   spawn dmenu)
		   ,((mod4Mask, xK_p),   spawn dmenu)
		   ,((mod4Mask, xK_F10), spawn "amixer set Master 10%-")
		   ,((mod4Mask, xK_F11), spawn "amixer set Master 10%+")]


myPP = xmobarPP { ppTitle = (\_ -> "")
                , ppHiddenNoWindows = xmobarColor "#2a2a2a" ""
                , ppLayout  = (\ x -> case x of
                            "Mirror Spacing Tall"          -> "[T]"
                            "Spacing Tall"                 -> "[D]"
                            "Full"                         -> "[M]"
                            _                              -> "|"++x++"|" )                

		, ppVisible = wrap "(" ")"
                , ppUrgent  = xmobarColor "red" "yellow"
                , ppCurrent = xmobarColor "#2a2a2a" "" . wrap "<" ">" }

toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
